package net;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;

public class TestTcpServer {

	public static void main(String[] args) throws Exception{
		int port=9000;
		ServerSocket server=new ServerSocket(port);
		while(true) {
			final Socket socket= server.accept();
			System.out.println("有一个客户连接成功了。。。。。");
			new Thread() {
				public void run() {
					try {
						OutputStream out=socket.getOutputStream();
						InputStream in=socket.getInputStream();
						BufferedReader reader=new BufferedReader(new InputStreamReader(in, "UTF-8"));
						out.write("Hello ,I am Server!!!\n".getBytes());
						String line=reader.readLine();
						System.out.println(line);
						reader.close();
						out.close();
						socket.close();
					}catch (Exception e) {
						e.printStackTrace();
					}
				};
			}.start();
		
		}
		
		
		//server.close();
	}

}
